package com.xhg.mqtt.job;

import com.xhg.mqtt.constant.MqttConstants;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import java.util.concurrent.TimeUnit;

/**
 * 线程池工具类
 */
public class ServicesPoolExecutor {

    // 服务线程池
    private static ExecutorService executorService = null;

    static {
        executorService = new ThreadPoolExecutor(MqttConstants.COREPOOLSIZE,
            MqttConstants.MAXIMUMPOOLSIZE, MqttConstants.KEEPALIVETIME, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(MqttConstants.CAPACITY),new CallerRunsPolicy());
    }

    public static ExecutorService getThreadPools() {
        return executorService;
    }


    public static void shutdownExecutor() {
        executorService.shutdown();
    }

}

